package 线程.demo13;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author wql
 * @version 1.0
 * @date 2022/11/1 17:02
 */

public class WqlLock implements Runnable{
    public int ticket=100;
  public static   ReentrantLock lock = new ReentrantLock();
    @Override
    public void run() {
        while (true){
            lock.lock();
            try {
                if (ticket>0){
                    System.out.println(Thread.currentThread().getName()+"买了一张票，剩余："+ --ticket);
                }
            }finally {
                lock.unlock();
            }
        }
    }
}
